package com.lh.blogTrivia.service.impl;

import com.lh.blogCommon.util.PageUtils;
import com.lh.blogCommon.util.Query;
import com.lh.blogTrivia.mapper.MusicMemorizingMapper;
import com.lh.blogTrivia.entity.MusicMemorizingEntity;
import com.lh.blogTrivia.service.MusicMemorizingService;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.util.StringUtils;


@Service
public class MusicMemorizingServiceImpl extends ServiceImpl<MusicMemorizingMapper, MusicMemorizingEntity> implements MusicMemorizingService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        QueryWrapper<MusicMemorizingEntity> queryWrapper = new QueryWrapper<>();

        String key = (String) params.get("key");
        System.out.println(params);
        if(!StringUtils.isEmpty(key)){
            queryWrapper.eq("memorizing_id",key).or()
                    .eq("song",key).or()
                    .eq("link", key).or()
                    .eq("acquaintance",key);

        }
        queryWrapper.orderByDesc("memorizing_id");

        IPage<MusicMemorizingEntity> page = this.page(
                new Query<MusicMemorizingEntity>().getPage(params),
                queryWrapper
        );

        return new PageUtils(page);
    }

}